<include file="Public/header" />
<title>添加账册</title>
</head>
<body>
<div class="pd-20">
<form action="__URL__/add_goods" name="postForm" id="postForm" enctype="multipart/form-data" method="post" >
	<table class="table table-border table-bordered table-bg">
		<tbody>
		<tbody>
			<tr class="text-c">
				<td width="15%" class="text-r" style="background-color:#f5f5f5">订单类型</td>
				<td class="text-l" width="35%">
					<select name="order_cate2" class="select input-text" style="width:150px;float:left;margin-right:5px;">
						<option value="0">---请选择---</option>
						<option value="1"<if condition="$detail['order_cate2'] eq 1">selected</if> >现货</option>
						<option value="2"<if condition="$detail['order_cate2'] eq 2">selected</if> >直邮</option>
						<option value="3"<if condition="$detail['order_cate2'] eq 3">selected</if> >保税</option>
					</select>
					<span style="line-height:30px;"><input type="checkbox" name="defaults1" />设为默认</span>
				</td>
				<td width="15%" class="text-r" style="background-color:#f5f5f5">订单编号</td>
				<td class="text-l" width="35%">
					<input type="text" readonly name="order_no" class="input-text" value="<{$serialNumber}>" >
				</td>
			</tr>
			<tr class="text-c">	
				<td width="15%" class="text-r" style="background-color:#f5f5f5">收件人姓名</td>
				<td class="text-l" width="35%">
					<input type="text" name="user_name" class="input-text" style="width:137px;float:left;" value="<{$detail.user_name.name}>" >
					<select name="idcard_id" class="select input-text" style="width:100px;float:left;margin-right:5px;">
						<option value="0">---请选择---</option>
						<foreach name="userlist" item="vo">
							<option value="<{$vo.id}>" <if condition="$detail['user_name']['id'] eq $vo['id']">selected</if> ><{$vo.name}></option>
						</foreach>
					</select>
					<span style="line-height:30px;"><input type="checkbox" name="defaults2"  />设为默认</span>
				</td>
				<td width="15%" class="text-r" style="background-color:#f5f5f5">发件人姓名</td>
				<td class="text-l">
					<input type="text" name="sendMan" class="input-text" style="width:137px;float:left;" value="<{$detail.sendMan.name}>" >
					<select name="sidcard_id" class="select input-text" style="width:100px;float:left;margin-right:5px;">
						<option value="0">---请选择---</option>
						<foreach name="userlist" item="vo">
							<option value="<{$vo.id}>" <if condition="$detail['sendMan']['id'] eq $vo['id']">selected</if> ><{$vo.name}></option>
						</foreach>
					</select>
					<span style="line-height:30px;"><input type="checkbox" name="defaults3"  />设为默认</span>
				</td>
			</tr>
			<tr class="text-c">	
				<td width="15%" class="text-r" style="background-color:#f5f5f5">收件人身份证号</td>
				<td class="text-l">
					<input type="text" name="user_idcard" class="input-text" value="<{$detail.user_name.no}>" >
				</td>
				<td width="15%" class="text-r" style="background-color:#f5f5f5"></td>
				<td class="text-l">
					
				</td>
			</tr>
			<tr class="text-c">	
				<td width="15%" class="text-r" style="background-color:#f5f5f5">收件人电话(手机号)</td>
				<td class="text-l" width="35%">
					<input type="text" name="user_phone" class="input-text" value="<{$detail.user_name.tel}>" >
				</td>
				<td width="15%" class="text-r" style="background-color:#f5f5f5">发件人电话(手机号)</td>
				<td class="text-l">
					<input type="text" name="sendManPhone" class="input-text" value="<{$detail.sendMan.tel}>" >
				</td>
			</tr>
			<tr class="text-c">
				<td width="15%" class="text-r" style="background-color:#f5f5f5">收件人省</td>
				<td class="text-l">
					<select name="province" class="select input-text" style="width:250px;float:left;margin-right:5px;">
						<option value="0">---请选择---</option>
						<foreach name="province_list" item="vo">
							<option value="<{$vo['code']}>"<if condition="$vo['code'] eq $detail['user_name']['province']">selected</if> ><{$vo.fullName}></option>
						</foreach>
					</select>
				</td>
				<td width="15%" class="text-r" style="background-color:#f5f5f5">发件人省</td>
				<td class="text-l">
					<select name="sendProvince" class="select input-text" style="width:250px;float:left;margin-right:5px;">
						<option value="0">---请选择---</option>
						<foreach name="province_list" item="vo">
							<option value="<{$vo['code']}>"<if condition="$vo['code'] eq $detail['sendMan']['province']">selected</if> ><{$vo.fullName}></option>
						</foreach>
					</select>
				</td>
			</tr>
			<tr class="text-c">
				<td width="15%" class="text-r" style="background-color:#f5f5f5">收件人市</td>
				<td class="text-l" width="35%">
					<select name="city" class="select input-text" style="width:250px;float:left;margin-right:5px;">
						<option value="0">---请选择---</option>
						<foreach name="city_list" item="vo">
							<option value="<{$vo['code']}>"<if condition="$vo['code'] eq $detail['user_name']['city']">selected</if> ><{$vo.fullName}></option>
						</foreach>
					</select>
				</td>
				<td width="15%" class="text-r" style="background-color:#f5f5f5">发件人市</td>
				<td class="text-l">
					<select name="sendCity" class="select input-text" style="width:250px;float:left;margin-right:5px;">
						<option value="0">---请选择---</option>
						<foreach name="send_city_list" item="vo">
							<option value="<{$vo['code']}>"<if condition="$vo['code'] eq $detail['sendMan']['city']">selected</if> ><{$vo.fullName}></option>
						</foreach>
					</select>
				</td>
			</tr>
			<tr class="text-c">
				<td width="15%" class="text-r" style="background-color:#f5f5f5">收件人区/县</td>
				<td class="text-l">
					<select name="area" class="select input-text" style="width:250px;float:left;margin-right:5px;">
						<option value="0">---请选择---</option>
						<foreach name="area_list" item="vo">
							<option value="<{$vo['code']}>"<if condition="$vo['code'] eq $detail['user_name']['area']">selected</if> ><{$vo.fullName}></option>
						</foreach>
					</select>
				</td>
				<td width="15%" class="text-r" style="background-color:#f5f5f5">发件人区/县</td>
				<td class="text-l">
					<select name="sendCounty" class="select input-text" style="width:250px;float:left;margin-right:5px;">
						<option value="0">---请选择---</option>
						<foreach name="send_area_list" item="vo">
							<option value="<{$vo['code']}>"<if condition="$vo['code'] eq $detail['sendMan']['area']">selected</if> ><{$vo.fullName}></option>
						</foreach>
					</select>
				</td>
			</tr>
			<tr class="text-c">
				<td width="15%" class="text-r" style="background-color:#f5f5f5">收件人详细地址</td>
				<td class="text-l">
					<input type="text" name="user_address" class="input-text" value="<{$detail.user_name.address}>" >
				</td>
				<td width="15%" class="text-r" style="background-color:#f5f5f5">发件人详细地址</td>
				<td class="text-l">
					<input type="text" name="sendManAddress" class="input-text" value="<{$detail.sendMan.address}>" >
				</td>
			</tr>
			
			<tr class="text-c">
				<td width="15%" class="text-r" style="background-color:#f5f5f5">运单号</td>
				<td class="text-l">
					<input type="text" name="logistics_no" class="input-text" value="<{$detail.logistics_no}>" >
				</td>
				<td width="15%" class="text-r" style="background-color:#f5f5f5">付款状态</td>
				<td class="text-l">
					<select name="pay_status" class="select input-text" style="width:150px;float:left;margin-right:5px;">
						<option value="0">---请选择---</option>
						<option value="1"<if condition="$detail['pay_status'] eq 1">selected</if> >已扣费</option>
						<option value="2"<if condition="$detail['pay_status'] eq 2">selected</if> >未扣费</option>
					</select>
					<span style="line-height:30px;"><input type="checkbox" name="defaults4"  />设为默认</span>
				</td>
			</tr>
			<tr class="text-c">
				<td width="15%" class="text-r" style="background-color:#f5f5f5">总价</td>
				<td class="text-l" width="35%">
					<input type="text" name="total_price" class="input-text" value="" >
				</td>				
				<td width="15%" class="text-r" style="background-color:#f5f5f5">状态</td>
				<td class="text-l" width="35%">
					<img src="__PUBLIC__/img/flag/flag_green.png">
					<input type="radio" name="flag" value="1" checked="">
					<img src="__PUBLIC__/img/flag/flag_yellow.png"></img>
					<input type="radio" name="flag" value="2">
					<img src="__PUBLIC__/img/flag/flag_red.png">
					<input type="radio" name="flag" value="3">
				</td>
			</tr>
			<tr class="text-c">
				<td width="15%" class="text-r" style="background-color:#f5f5f5">备注1</td>
				<td class="text-l" width="35%">
					<textarea name="mark1" class="textarea" ><{$detail.mark1}></textarea>
				</td>
				<td width="15%" class="text-r" style="background-color:#f5f5f5">备注2</td>
				<td class="text-l" width="35%">
					<textarea name="mark2" class="textarea" ><{$detail.mark2}></textarea>
				</td>
			</tr>
		</tbody>
		</tbody>
	</table>
	<input type="button" class="btn btn-primary radius mt" id="b_add" value="添加">
</form>
</div>
<script type="text/javascript" src="__PUBLIC__/js/jquery.form.js"></script>
<script>
$(function(){
		//订单类型
		$('input[name=defaults1]').change(function(){
				status=$(this).prop('checked');
				val=$('select[name=order_cate2]').find('option:selected').val();
				$.ajax({
					type:'POST',
					data:{val:val,status:status},
					url:"<{:U('defaults1')}>",
					success:function(data){
						layer.msg(data.message);
					}
				})
		})
		//收件人姓名
		$('input[name=defaults2]').change(function(){
				status=$(this).prop('checked');
				val=$('select[name=idcard_id]').find('option:selected').val();
				$.ajax({
					type:'POST',
					data:{val:val,status:status},
					url:"<{:U('defaults2')}>",
					success:function(data){
						layer.msg(data.message);
					}
				})
		})
		//发件人姓名
		$('input[name=defaults3]').change(function(){
				status=$(this).prop('checked');
				val=$('select[name=sidcard_id]').find('option:selected').val();
				$.ajax({
					type:'POST',
					data:{val:val,status:status},
					url:"<{:U('defaults3')}>",
					success:function(data){
						layer.msg(data.message);
					}
				})
		})
		//付款状态
		$('input[name=defaults4]').change(function(){
				status=$(this).prop('checked');
				val=$('select[name=pay_status]').find('option:selected').val();
				$.ajax({
					type:'POST',
					data:{val:val,status:status},
					url:"<{:U('defaults4')}>",
					success:function(data){
						layer.msg(data.message);
					}
				})
		})
		$("select[name=province]").change(function(){
				$.ajax({
					type: 'POST',
					data: {code:$(this).val()},
					url: "<{:U('city_list')}>",
					success:function(data){
						<!-- console.log(data.message.length); -->
						if(data.status==1){
							$("select[name=city]").find('option').remove();
							$("select[name=area]").find('option').remove();
							$("select[name=area]").append("<option value='0'>---请选择---</option>");
							$("select[name=city]").append("<option value='0'>---请选择---</option>");
							for(i=0;i<data.message.length;i++){
								html="<option value='"+data.message[i].code+"'>"+data.message[i].fullName+"</option>";
								$("select[name=city]").append(html);
							}
						}else{			
							layer.msg(data.message);
						}
						return false;
					}
				})
			})
			$("select[name=city]").change(function(){
				$.ajax({
					type: 'POST',
					data: {code:$(this).val()},
					url: "<{:U('area_list')}>",
					success:function(data){
						if(data.status==1){
							$("select[name=area]").find('option').remove();
							$("select[name=area]").append("<option value='0'>---请选择---</option>");
							for(i=0;i<data.message.length;i++){
								html="<option value='"+data.message[i].code+"'>"+data.message[i].fullName+"</option>";
								$("select[name=area]").append(html);
							}
						}else{			
							layer.msg(data.message);
						}
						return false;
					}
				})
			})
			$("select[name=sendProvince]").change(function(){
				$.ajax({
					type: 'POST',
					data: {code:$(this).val()},
					url: "<{:U('city_list')}>",
					success:function(data){
						<!-- console.log(data.message.length); -->
						if(data.status==1){
							$("select[name=sendCity]").find('option').remove();
							$("select[name=sendCounty]").find('option').remove();
							$("select[name=sendCounty]").append("<option value='0'>---请选择---</option>");
							$("select[name=sendCity]").append("<option value='0'>---请选择---</option>");
							for(i=0;i<data.message.length;i++){
								html="<option value='"+data.message[i].code+"'>"+data.message[i].fullName+"</option>";
								$("select[name=sendCity]").append(html);
							}
						}else{			
							layer.msg(data.message);
						}
						return false;
					}
				})
			})
			$("select[name=sendCity]").change(function(){
				$.ajax({
					type: 'POST',
					data: {code:$(this).val()},
					url: "<{:U('area_list')}>",
					success:function(data){
						if(data.status==1){
							$("select[name=sendCounty]").find('option').remove();
							$("select[name=sendCounty]").append("<option value='0'>---请选择---</option>");
							for(i=0;i<data.message.length;i++){
								html="<option value='"+data.message[i].code+"'>"+data.message[i].fullName+"</option>";
								$("select[name=sendCounty]").append(html);
							}
						}else{			
							layer.msg(data.message);
						}
						return false;
					}
				})
			})
	$("select[name=idcard_id]").change(function(){
		var user_name=$("input[name=user_name]");
		var user_idcard=$("input[name=user_idcard]");
		var user_phone=$("input[name=user_phone]");
		var province=$("select[name=province]");
		var city=$("select[name=city]");
		var area=$("select[name=area]");
		var user_address=$("input[name=user_address]");
		
		if($(this).val()!=0){
			user_name.attr('readonly','readonly');
			user_name.val($(this).find("option:selected").text());
			$.ajax({
				type: 'POST',
				data: {idcard_id:$(this).val()},
				url: "<{:U('idcard_info')}>",
				success:function(data){
					console.log(data);
					if(data.status==1){	
							var message=data.message;
							user_idcard.val(message.no);
							user_phone.val(message.tel);
							province.val(message.province);
							city.find('option').remove();
							city.append("<option value='"+message.city+"'>"+message.city_name+"</option>");
							area.find('option').remove();
							area.append("<option value='"+message.area+"'>"+message.area_name+"</option>");
							user_address.val(message.address);
					}else{			
						layer.msg(data.message);
					}
					return false;
				}
			})
		}else{
			user_name.removeAttr('readonly');
			user_name.val('');
			user_idcard.val('');
			user_phone.val('');
			province.val(0);
			city.find('option').remove();
			city.append("<option value='0'>---请选择---</option>");
			area.find('option').remove();
			area.append("<option value='0'>---请选择---</option>");
			user_address.val('');
		}
	})
	$("select[name=sidcard_id]").change(function(){		
		var sendMan=$("input[name=sendMan]");
		var sendManPhone=$("input[name=sendManPhone]");
		var sendProvince=$("select[name=sendProvince]");
		var sendCity=$("select[name=sendCity]");
		var sendCounty=$("select[name=sendCounty]");
		var sendManAddress=$("input[name=sendManAddress]");
		
		if($(this).val()!=0){
			sendMan.attr('readonly','readonly');
			sendMan.val($(this).find("option:selected").text());
			$.ajax({
				type: 'POST',
				data: {idcard_id:$(this).val()},
				url: "<{:U('idcard_info')}>",
				success:function(data){
					console.log(data);
					if(data.status==1){	
							var message=data.message;
							sendManPhone.val(message.tel);
							sendProvince.val(message.province);
							sendCity.find('option').remove();
							sendCity.append("<option value='"+message.city+"'>"+message.city_name+"</option>");
							sendCounty.find('option').remove();
							sendCounty.append("<option value='"+message.area+"'>"+message.area_name+"</option>");
							sendManAddress.val(message.address);
					}else{			
						layer.msg(data.message);
					}
					return false;
				}
			})
		}else{
			sendMan.removeAttr('readonly');
			sendMan.val('');
			sendManPhone.val('');
			sendProvince.val(0);
			sendCounty.find('option').remove();
			sendCounty.append("<option value='0'>---请选择---</option>");
			sendCity.find('option').remove();
			sendCity.append("<option value='0'>---请选择---</option>");
			sendManAddress.val('');
		}
	})
	$("#b_add").click(function() { 
        $("#postForm").ajaxSubmit({  
            url: "<{:U('add_orders')}>",
            type : "post",  
            dataType : 'json',  
            success : function(data) {
				if(data.status==1){
					layer.msg(data.message,function(){
						parent.window.location.href =parent.window.location.href;
					});
				}else{
					layer.msg(data.message);
				}
                
            },
            error : function(data) {  
                layer.msg('出错');
            }  
        });  
    });
});
</script>

</body>
</html>